import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Jjn
 * @since 2021-06-12 13:38
 */
public class Solution26_1 {
    public int removeDuplicates(int[] nums) {
        if (nums == null) {
            return 0;
        }
        int length = nums.length;
        Set<Integer> set = new HashSet<>(length, 1);
        int j = 0;
        for (int i = 0; i < length; i++) {
            int num = nums[i];
            if (!set.contains(num)) {
                set.add(num);
                nums[j] = nums[i];
                j++;
            }
        }
        return j;
    }
    
    public static void main(String[] args) {
        Solution26_1 solution261 = new Solution26_1();
        int[] ints = {1, 2, 3, 4, 5, 6, 6, 4, 3, 2, 1};
        System.out.println(solution261.removeDuplicates(ints));
    }
}
